﻿function IFSHelper() {
    this.getLive = function (func) {

        var selMatch = "";
        if (selMatch == ",,,")
            selMatch = "";
        var myconfig = "";
        
        var ds = [];
        if (selMatch != "")
            selMatch = "," + selMatch + ",";
        for (var j = 0; j < ORD.length; ++j) {
            var i = ORD[j];
            if (typeof (sDt[i]) == "object") {
                if (selMatch != "") {
                    if (selMatch.indexOf("," + sDt[i][16] + ",") == -1) {
                        continue;
                    }
                }
                if (typeof (sDt2[i]) == "object") {
                    var d = {};
                    d["bh"] = i;
                    d["gl"] = sDt[i][0];
                    d["cr"] = sDt[i][1];
                    d["live_a"] = sDt[i][2];
                    d["live_b"] = sDt[i][3];
                    d["memo"] = sDt[i][4];
                    d["weather"] = sDt[i][5];
                    d["wd"] = sDt[i][6];
                    d["pm1"] = sDt[i][7];
                    d["pm2"] = sDt[i][8];
                    d["abh"] = isdecimalblank(sDt[i][9]);
                    d["bbh"] = isdecimalblank(sDt[i][10]);
                    d["glbh"] = isdecimalblank(sDt[i][12]);
                    d["bir"] = isdecimalblank(sDt[i][13]);
                    d["r_bh"] = isdecimalblank(sDt[i][14]);
                    d["r_bir"] = isdecimalblank(sDt[i][15]);
                    d["isstart"] = isdecimalblank(sDt2[i][0]);
                    d["isFinishLive"] = Isfinish(sDt2[i][0]);
                    d["la"] = isdecimalblank(sDt2[i][1]);
                    d["lb"] = isdecimalblank(sDt2[i][2]);
                    d["ra"] = isdecimalblank(sDt2[i][3]);
                    d["rb"] = isdecimalblank(sDt2[i][4]);
                    d["diftime"] = sDt2[i][5];
                    d["bc"] = sDt2[i][1] + "-" + sDt2[i][2];
                    d["resume"] = sDt2[i][7];
                    d["sj"] = ConvertDate(sDt2[i][8]);
                    d["sx"] = isdecimalblank(sDt2[i][9]);
                    d["rq"] = isdecimalblank(sDt2[i][10]);
                    d["sw1"] = isdecimalblank(sDt2[i][11]);
                    d["sw2"] = isdecimalblank(sDt2[i][12]);
                    d["sy"] = isdecimalblank(sDt2[i][13]);
                    d["euro1x2"] = isdecimalblank(sDt[i][17]);
                    d["pk2"] = sDt[i][18];
                    d["mb_pk"] = sDt[i][19];
                    d["cb_pk"] = sDt[i][20];

                    ds.push(d);

                    //Wr(i, sDt[i][0], sDt[i][1], sDt[i][2], sDt[i][3], sDt[i][4], sDt[i][5], sDt[i][6], sDt[i][7], sDt[i][8], sDt[i][9], sDt[i][10], sDt[i][11],
                    //sDt[i][12], sDt[i][13], sDt[i][14], sDt[i][15], sDt2[i][0], sDt2[i][1], sDt2[i][2], sDt2[i][3], sDt2[i][4], sDt2[i][5], sDt2[i][6],
                    //sDt2[i][7], sDt2[i][8], sDt2[i][9], sDt2[i][10], sDt2[i][11], sDt2[i][12], sDt2[i][13], sDt[i][17], sDt[i][18]);
                }
            }
        }

        AysPost("AddLive",
            JSON.stringify(ds),
            func);
        ds = [];
    };
}

this.isdecimalblank = function (data) {
    if (data == undefined || data == '') {
        return -99;
    }
    else {
        return data;
    }

}
this.ConvertDate = function(date) {
    var p_ssj = date.split(",");
    var p_sj = new Date(p_ssj[0], parseFloat(p_ssj[1]) - 1, p_ssj[2], p_ssj[3], p_ssj[4], p_ssj[5]);
    return p_sj;
}

this.Isfinish = function (isstart) {
    if (isstart == 4 || isstart == 6 || isstart == 10 || (isstart >= 12 && isstart <= 15)) {
        return true;
    }
    else {
        return false;
    }
    
}
this.AysPost = function (_methodName, _postData, func, async) {
    //waitingDialog({ title: "Loading...", message: "Please wait." });
    var domain = "/ifs.ashx";
    var Async = false;
    if (async == false) {
        Async = false;
    }
    var _data = { metdhodName: _methodName, postData: _postData };
    var uriPost = domain;
    jQuery.ajax({
        type: "POST",
        url: uriPost,
        async: Async,
        data: _data,
        dataType: "json",
        success: function (data) {
            if (func) {
                if (data && data.Error === '-0') {
                    window.location = '/Page/login.aspx';
                }
                func(data);
            }
        },
        error: function () {
            //closeWaitingDialog();
        }
    });
};